#Title[ZtO̘Z]
#Text[@_}[i]
#PlayLevel[EXTRA]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\yuyuko.dnh"

	let name = "Ztutmuxāv";

	xIni = cx;
	yIni = GetClipMinY + 128;

	sub onInitialize {
		CutIn(YOUMU, name, bossCut, 1, 1, 463, 655);
		SetScore(10000000);
		SetLife(2000);
		SetDamageRate(0, 0);
		SetTimer(75);
		back = CSD ~ "img\back5.png";

		TMain;
	}

	sub onMainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		yield;
	}

	sub onDrawLoop {
	}

	sub onFinalize {
		DeleteGraphic(bossImg);
		PlaySE(seFin);
	}

/////////////////////////////////////////////////////////////////////

	task TMain {
		getReady(120);
		SetDamageRate(50, 50);

		let count = 0;

		loop {
			SetAction(ACT_SHOT_B, 90);
			loop(count * 8 + 8) {
				CreateEnemyFromScript("creature", GetX, GetY, rand(1, 2), rand(0, 360), 0);
			}
			wait(600 - count * 15);
			count++;
		}
	}
	#include_function ".\lib\ZtObody.dnh"
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

script_enemy creature {
	#include_function ".\lib\ZtOCommon_.dnh"

	let angle = GetAngle;
	let speed = GetSpeed;

	let x = GetX;
	let y = GetY;

	let obj = createObjShot_(x, y, speed, angle, BUTTER, rand_int(0, 7), 0);

	@Initialize {
		SetScore(50000);
		SetLife(1);
		SetDamageRate(0, 0);

		TMain;
	}

	@MainLoop {
		x += cos(angle) * speed;
		y += sin(angle) * speed;
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		SetX(x);
		SetY(y);
		SetCollisionA(x, y, 8);
		yield;
	}

	@DrawLoop {}

	@Finalize {
		if(GetEnemyLife > 1) {
			loop(180) {
				createNmlShot01_(x, y, rand(0.5, 3), rand(0, 360), GRAIN, WHITE, -1);
			}
		}
		Obj_Delete(obj);
	}

/////////////////////////////////////////////////////////////////////

	task TMain {
		wait(90);
		SetDamageRate(100, 100);

		angle = atan2(GetPlayerY - y, GetPlayerX - x);
		speed = 1;
	}
}